﻿@inject SqlContext _context;
@inject BaseWebElement _baseElement;
@model Product_Info
@{
    var CompanyName = _baseElement.GetWebElement(WebElementType.CompanyName)?.Value;
    ViewData["Title"] = Model.ProName + " - " + CompanyName;
    int pId = (int)ViewData["pid"];
    var product = Model;
    int lanid = _baseElement.Currentlanguage.Id;
    var LocationClass = _baseElement.GetCurrentRoute(Model.ClassId);
    var CurrentlanguageclassHref = _baseElement.GetCurrentlanguageclassHref();
    var relevants = _context.QueryPageList<Product_Info>(e => e.ClassId == product.ClassId && e.Id != product.Id, "random()", 1, 4);
    ViewData["keywords"] = Model.SeoKeywords;
    ViewData["description"] = Model.SeoDescription;
}
@functions{
    public string GetProductTitleImg(int proId)
    {
        var imgInfo = _context.QueryInfo<Product_Img>(m => m.ProId == proId, "IsTitle desc");
        if (imgInfo != null)
        {
            return imgInfo.Img;
        }
        else
        {
            return "";
        }
    }
}
<div class="wrapper">
    <div class="crumbs">
        <div class="container">
            <p class="weizhi">
                @(_baseElement.QueryLanText("Location"))：<a href="@(CurrentlanguageclassHref)">@(_baseElement.QueryLanText("Home"))</a>
                @if (LocationClass != null && LocationClass.Count > 0)
                {
                    foreach (var item in LocationClass)
                    {
                        @Html.Raw("&gt")<a href="@(item.ClassHref)">@item.ClassName</a>
                    }
                }
                @Html.Raw("&gt")<a href="javascript:;">@Model.ProName</a>
            </p>
        </div>
    </div>
    <div class="proDot">
        <div class="container">
            <div class="proInfoTop">
                <div class="row">
                    <div class="col-md-5 col-xs-12">
                        <div class="proImg">
                            <img src="@GetProductTitleImg(product.Id)" />
                        </div>
                    </div>
                    <div class="col-md-7 col-xs-12">
                        <div class="proTxt">
                            <h1>@product.ProName</h1>
                            <ul class="clearfix">
                                @if (!product.CasNo.IsNullOrWhiteSpace())
                                {
                                    <li><span>@_baseElement.QueryLanText("pd_casno")</span><em>@product.CasNo</em></li>
                                }
                                @if (!product.MolecularFormula.IsNullOrWhiteSpace())
                                {
                                    <li><span>@_baseElement.QueryLanText("pd_formula", lanid)</span><em>@product.MolecularFormula</em></li>
                                }
                                @if (!product.Molecularweight.IsNullOrWhiteSpace())
                                {
                                    <li><span>@_baseElement.QueryLanText("pd_molecularWeight", lanid)</span><em>@product.Molecularweight</em></li>
                                }
                                @if (!product.Purity.IsNullOrWhiteSpace())
                                {
                                    <li><span>@_baseElement.QueryLanText("pd_purity", lanid)</span><em>@product.Purity</em></li>
                                }
                                @if (!product.Packaging.IsNullOrWhiteSpace())
                                {
                                    <li><span>@_baseElement.QueryLanText("pd_packing", lanid)</span><em>@product.Packaging</em></li>
                                }
                                @if (!product.Appearance.IsNullOrWhiteSpace())
                                {
                                    <li><span>@_baseElement.QueryLanText("pd_appearance", lanid)</span><em>@product.Appearance</em></li>
                                }
                            </ul>

                        </div>
                        <a href="javascript:;" class="inquiryBtn">@_baseElement.QueryLanText("pd_inquiry", lanid)</a>
                    </div>
                </div>

            </div>
            <div class="proDetail">
                <div class="proTit">
                    <p><span>@_baseElement.QueryLanText("pd_detail", lanid)</span></p>
                </div>
                <div class="infoBox">
                    <h3><span></span>@_baseElement.QueryLanText("pd_quickdetail", lanid)</h3>
                    <ul class="clearfix">
                        @if (!product.CasNo.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_casno")： </em><span title="@product.CasNo">@product.CasNo</span></li>
                        }
                        @if (!product.MolecularFormula.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_formula")： </em><span title="@product.MolecularFormula">@product.MolecularFormula</span></li>
                        }
                        @if (!product.Appearance.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_appearance")： </em><span title="@product.Appearance">@product.Appearance</span></li>
                        }
                        @if (!product.DeliveryTime.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_deliveryTime")： </em><span title="@product.DeliveryTime">@product.DeliveryTime</span></li>
                        }
                        @if (!product.Packaging.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_packing")： </em><span title="@product.Packaging">@product.Packaging</span></li>
                        }
                        @if (!product.ProductionCapacity.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_throughput")： </em><span title="@product.ProductionCapacity">@product.ProductionCapacity</span></li>
                        }
                        @if (!product.Purity.IsNullOrWhiteSpace())
                        {
                            <li><em>@_baseElement.QueryLanText("pd_purity")： </em><span title="@product.Purity">@product.Purity</span></li>
                        }
                    </ul>
                </div>
                <div class="infoBox">
                    @Html.Raw(product.Description)
                </div>
            </div>
            @if (relevants.count > 0)
            {
                <div class="proRec">
                    <div class="tit">
                        <h2>@_baseElement.QueryLanText("pd_relevantProduct", lanid)</h2>
                        <span></span>
                    </div>
                    <ul class="proLis clearfix">
                        @{
                            foreach (var item in relevants.data)
                            {
                                <li>
                                    <div class="imgBox">
                                        <a href="@(CurrentlanguageclassHref)products/detail/@(item.Id).html"><img src="@GetProductTitleImg(item.Id)"></a>
                                    </div>
                                    <div class="txtBox">
                                        <a href="@(CurrentlanguageclassHref)products/detail/@(item.Id).html">@item.ProName</a>
                                        @if(!item.CasNo.IsNullOrWhiteSpace())
                                        {
                                            <P>CAS：@item.CasNo</P>
                                        }
                                    </div>
                                </li>
                            }
                        }
                    </ul>
                </div>
            }
            <div class="inquiryBox">
                <div>
                    <div class="inputLi">
                        <label>
                            <p>@_baseElement.QueryLanText("pd_proname")</p>
                            <input type="text" name="proname" value="@product.ProName" />
                        </label>
                    </div>
                    <div class="inputLi">
                        <label>
                            <p><sup>*</sup>@_baseElement.QueryLanText("Email")</p>
                            <input type="email" name="email" placeholder="@_baseElement.QueryLanText("Message_email")" />
                        </label>
                    </div>
                    <div class="inputLi">
                        <label>
                            <p>@_baseElement.QueryLanText("CompanyName")</p>
                            <input type="text" name="company" placeholder="@_baseElement.QueryLanText("Message_company")" />
                        </label>
                    </div>
                    <div class="inputLi">
                        <label>
                            <p>@_baseElement.QueryLanText("Description")</p>
                            <textarea name="content" placeholder="@_baseElement.QueryLanText("Description")"></textarea>
                        </label>
                    </div>
                    <button onclick="PostMessage()" class="submit inquiryBtn">@_baseElement.QueryLanText("Submit")</button>
                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script type="text/javascript">

        $(document).ready(function (e) {
            $(".proInfoTop .inquiryBtn").click(function () {
                $(".inquiryBox").stop().show();
                $("body").addClass("mask");

            });
            function stopPropagation(e) {
                if (e.stopPropagation)
                    e.stopPropagation();
                else
                    e.cancelBubble = true;
            }
            $(document).bind('click', function () {
                $("body").removeClass("mask")
                $(".inquiryBox").stop().hide();
            });

            $(".inquiryBox").bind('click', function (e) {
                stopPropagation(e);
            });
            $(".proInfoTop .inquiryBtn").bind('click', function (e) {
                stopPropagation(e);
            });
        });

        function PostMessage() {
            var data = {
                email: $("[name=email]").val(),
                company: $("[name=company]").val(),
                content: "Product Name: "+$("[name=proname]").val()+"\n"+$("[name=content]").val(),
                language:@(_baseElement.Currentlanguage.Id)
            };
            if (data.email == null || data.email == "") {
                alert("@_baseElement.QueryLanText("Message_email")");
                return false;
            }
            $.ajax({
                url: "/ajax/PostInquiry",
                type: "post",
                data: JSON.stringify(data),
                contentType: "application/json",
                dataType: "json",
                success: function (result) {
                    alert(result.message)
                    if (result.success) {
                        window.location.reload();
                    }
                }
            });
            return false;
        }
    </script>
}